package com.gs.wzmanager.dao;


import com.gs.wzmanager.bo.Threshold;
import com.gs.wzmanager.dao.mapper.ForeThresholdMapper;
import com.gs.wzmanager.entity.ForeThreshold;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ForeThresholdDao {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    ForeThresholdMapper mapper;

    public boolean add(ForeThreshold foreThreshold) {
    try {
            mapper.addForeThreshold(foreThreshold);
            return true;
        } catch (Exception e) {
            logger.info("DisasterForecastDao：add->{}", e.getMessage());
            return false;
        }
    }

    public boolean delete(int id) {
        try {
            mapper.deleteForeThreshold(id);
            return true;
        } catch (Exception e) {
            logger.info("DisasterForecastDao：delete失败->{}", e.getMessage());
            return false;
        }
    }

    public boolean update(ForeThreshold foreThreshold) {

        /*
            ForeThreshold df = new ForeThreshold();
            df.setId(1000);
            df.setName("修改");
            df.setThreshold((double) 20);
        */

        try {
            mapper.updateForeThreshold(foreThreshold);
            return true;
        } catch (Exception e) {
            logger.info("DisasterForecastDao：update->{}", e.getMessage());
            return false;
        }
    }

    public List<ForeThreshold> queryForeThresholdByStationName(String station) {
        try {
            return mapper.queryForeThresholdByStationName(station);
        } catch (Exception e) {
            logger.info("DisasterForecastDao：queryForeThresholdByStationName失败->{}", e.getMessage());
            return null;
        }
    }

    public List<Threshold> queryThreshold(){
        try {
            return mapper.queryThreshold();
        } catch (Exception e) {
            logger.info("DisasterForecastDao：queryThreshold->{}", e.getMessage());
            return null;
        }
    }
}
